import 'package:go_router/go_router.dart';
import 'package:leader_doctor_flutter/common/widget/imgae_gallery.dart';
import 'package:leader_doctor_flutter/test/function_test.dart';
import 'package:leader_doctor_flutter/test/url_test.dart';

import 'package:leader_doctor_flutter/ui/mine/page/my_doctor_service.dart';
import 'package:leader_doctor_flutter/ui/mine/page/my_doctor_service_details.dart';
import 'package:leader_doctor_flutter/ui/mine/page/my_doctor_service_refund_application.dart';
import 'package:leader_doctor_flutter/ui/mine/page/my_project_outcome.dart';

import 'package:leader_doctor_flutter/ui/mine/page/consultation_detail.dart';
import 'package:leader_doctor_flutter/ui/mine/page/consultation_record.dart';
import 'package:leader_doctor_flutter/ui/mine/page/my_gift.dart';
import 'package:leader_doctor_flutter/ui/mine/page/my_info_main.dart';
import 'package:leader_doctor_flutter/ui/mine/page/prescription_preview.dart';

import 'package:leader_doctor_flutter/ui/mine/page/prescription_record.dart';
import 'package:leader_doctor_flutter/ui/prescription/page/illnessClassify.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/wallet_forgot_password.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/wallet_set_password.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/wallet_withdrawal_record.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/authentication.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/income_detail.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/income_list.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/wallet_reflect.dart';
import 'package:leader_doctor_flutter/ui/setting/page/about.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/bank_card_manage.dart';
import 'package:leader_doctor_flutter/ui/setting/page/bind_phone_num.dart';
import 'package:leader_doctor_flutter/ui/setting/page/feed_back.dart';
import 'package:leader_doctor_flutter/ui/setting/page/modify_phone_num.dart';
import 'package:leader_doctor_flutter/ui/task/meeting/page/meeting_yunxin.dart';
import 'package:leader_doctor_flutter/ui/wallet/page/wallet_security_verification.dart';

import '../test/scroll_test.dart';
import '../model/consult.dart';
import '../ui/mine/page/protocol_list.dart';
import '../ui/mine/page/sign_history.dart';
import '../ui/mine/page/study_record.dart';
import '../ui/setting/page/modify_pass.dart';
import '../ui/splash.dart';
import '../ui/setting/page/setting_main.dart';
import '../ui/setting/page/cancel _account.dart';
import '../ui/task/meeting/page/workstation.dart';
import '../ui/wallet/page/wallet_main.dart';

/// @Author lixiaobin
/// @Date 2023/11/3
/// @Description
class PageUrl {
  static const splash = '/';
  static const home = '/home';
  static const urlTest = '/test/url';
  static const functionTest = '/test/function';
  static const scrollTest = '/test/scroll/function';
  static const about = '/setting/about';
  static const modifyPass = '/setting/modifyPass';
  static const modifyPhoneNum = '/setting/modifyPhoneNum';
  static const bindPhoneNum = '/setting/bindPhoneNum';
  static const studyRecord = '/mine/studyRecord';
  static const signHistory = '/mine/signHistory';
  static const walletPwd = '/mine/walletPwd';
  static const walletMain = '/mine/walletMain';
  static const walletReflect = '/mine/walletReflect';
  static const walletIncomeList = '/mine/walletIncomeList';
  static const walletIncomeDetail = '/mine/walletIncomeDetail';
  static const meeting = '/meeting/neteaseMeeting';
  static const settingMain = '/setting/settingMain';
  static const cancelAccount = '/setting/cancelAccount';
  static const bankCardManage = '/setting/bankCardManage';
  static const feedBack = '/setting/feedBack';
  static const myGift = '/mine/myGift';
  static const walletWithdrawalRecord = '/mine/walletWithdrawalRecord';
  static const walletForgotPassword = '/mine/WalletForgotPassword';

  static const walletSetPassword = "/mine/WalletSetPasswordPage";

  static const prescriptionRecord = "/mine/prescriptionRecord";
  static const projectOutcome = "/mine/myProjectOutcome";
  static const doctorService = "/mine/myDoctorService";
  static const doctorServiceDetails = "/mine/myDoctorServiceDetails";
  static const doctorServiceRefundApplicationList = "/mine/myDoctorServiceRefundApplicationList";

  static const prescriptionPreView = '/mine/prescriptionPreView';
  static const consultationRecord = '/mine/consultationRecord';
  static const consultationDetail = '/mine/consultationDetail';
  static const browseImage = '/browse/images';

  static const workstation = "/home/workstation";
  static const walletMain1 = "/mine/walletMain1";
  static const walletSecurityVerification = "/mine/walletSecurityVerificationPage";
  static const myInfoMain = "/mine/myInfoMain";
  static const myProtocolList = "/mine/protocolList";
  static const illnessClassify = "/prescription/illnessClassify";
}

/// The route configuration.
final GoRouter appRouter = GoRouter(
  routes: [
    GoRoute(
      name: '引导',
      path: PageUrl.splash,
      builder: (context, state) => const SplashPage(),
    ),
    GoRoute(
      name: '关于',
      path: PageUrl.about,
      builder: (context, state) => const AboutPage(),
    ),
    GoRoute(
      name: '学习记录',
      path: PageUrl.studyRecord,
      builder: (context, state) => const StudyRecordPage(),
    ),
    GoRoute(
      name: '签约记录',
      path: PageUrl.signHistory,
      builder: (context, state) => const SignHistoryPage(),
    ),
    GoRoute(
      name: 'url测试',
      path: PageUrl.urlTest,
      builder: (context, state) => const UrlTestPage(),
    ),
    GoRoute(
      name: '方法测试',
      path: PageUrl.functionTest,
      builder: (context, state) => const FunctionTest(),
    ),
    GoRoute(
      name: '滑动测试',
      path: PageUrl.scrollTest,
      builder: (context, state) => const ScrollTestPage(),
    ),
    GoRoute(
      name: '会议',
      path: PageUrl.meeting,
      builder: (context, state) {
        var mdtId = state.queryParams['mdtId'] ?? '';
        return MeetingPage(mdtId: mdtId);
      },
    ),
    GoRoute(
      name: '修改登录密码',
      path: PageUrl.modifyPass,
      builder: (context, state) => const ModifyPassPage(),
    ),
    GoRoute(
      name: '更换手机号',
      path: PageUrl.modifyPhoneNum,
      builder: (context, state) => const ModifyPhoneNumPage(),
    ),
    GoRoute(
      name: '绑定新手机号',
      path: PageUrl.bindPhoneNum,
      builder: (context, state) => const BindPhoneNumPage(),
    ),
    GoRoute(
      name: '银行卡管理',
      path: PageUrl.bankCardManage,
      builder: (context, state) {
        return const BankCardManagePage();
      },
    ),
    GoRoute(
      name: '意见反馈',
      path: PageUrl.feedBack,
      builder: (context, state) => const FeedBackPage(),
    ),
    GoRoute(
      name: '设置',
      path: PageUrl.settingMain,
      builder: (context, state) => const SettingMainPage(),
    ),
    GoRoute(
      name: '注销账号',
      path: PageUrl.cancelAccount,
      builder: (context, state) => const CancelAccountPage(),
    ),
    GoRoute(
      name: '我的礼物',
      path: PageUrl.myGift,
      builder: (context, state) => const MyGiftPage(),
    ),
    GoRoute(
      name: '提现记录',
      path: PageUrl.walletWithdrawalRecord,
      builder: (context, state) => const WalletWithdrawalRecordPage(),
    ),
    GoRoute(
      name: '找回密码',
      path: PageUrl.walletForgotPassword,
      builder: (context, state) => const WalletForgotPasswordPage(),
    ),
    GoRoute(
      name: '密码验证',
      path: PageUrl.walletPwd, // 新版钱包设置密码和密码验证是一个页面
      builder: (context, state) {
        // setPassword = 1：设置密码，setPassword = 0: 密码验证
        var setPassword = state.queryParams['setPassword'] ?? '0';
        return AuthenticationPage(setPassword: setPassword);
      },
    ),
    GoRoute(
      name: '我的钱包',
      path: PageUrl.walletMain,
      builder: (context, state) => const WalletMainPage(),
    ),
    GoRoute(
      name: '提现',
      path: PageUrl.walletReflect,
      builder: (context, state) => const WalletReflectPage(),
    ),
    GoRoute(
      name: '收入明细',
      path: PageUrl.walletIncomeList,
      builder: (context, state) => const IncomeListPage(),
    ),
    GoRoute(
      name: '交易明细',
      path: PageUrl.walletIncomeDetail,
      builder: (context, state) {
        var sourceType = state.queryParams['subOrderNo'] ?? '1';
        return IncomeDetailPage(subOrderNo: sourceType);
      },
    ),
    GoRoute(
      name: '设置密码', // 新版钱包的设置密码页面不再用此页面 废弃
      path: PageUrl.walletSetPassword,
      builder: (context, state) => const WalletSetPasswordPage(),
    ),
    GoRoute(
      name: '开单记录',
      path: PageUrl.prescriptionRecord,
      builder: (context, state) => const PrescriptionRecordPage(),
    ),
    GoRoute(
      name: '项目成果',
      path: PageUrl.projectOutcome,
      builder: (context, state) => const MyProjectOutcomePage(),
    ),
    GoRoute(
      name: '医生服务',
      path: PageUrl.doctorService,
      builder: (context, state) => const MyDoctorServicePage(),
    ),
    GoRoute(
      name: '查看详情',
      path: PageUrl.doctorServiceDetails,
      builder: (context, state) {
        var listId = state.queryParams['id'] ?? "";
        return MyDoctorServiceDetailsPage(listId: listId);
      },
    ),
    GoRoute(
      name: '退款申请',
      path: PageUrl.doctorServiceRefundApplicationList,
      builder: (context, state) => const MyDoctorServiceRefundApplicationPage(),
    ),
    GoRoute(
      name: '处方单',
      path: PageUrl.prescriptionPreView,
      builder: (context, state) {
        var prescriptionNo = state.queryParams['prescriptionNo'] ?? '';
        return PrescriptionPreViewPage(prescriptionNo: prescriptionNo);
      },
    ),
    GoRoute(
      name: '咨询记录',
      path: PageUrl.consultationRecord,
      builder: (context, state) => const ConsultationRecordPage(),
    ),
    GoRoute(
      name: '查看图片',
      path: PageUrl.browseImage,
      builder: (context, state) {
        var extra = state.extra;
        int? selectIndex = 0;
        List<String> arr = [];
        if (extra is List) {
          arr = extra as List<String>;
        } else if (extra is Map) {
          arr = extra['imgArr'] as List<String>;
          selectIndex = extra['selectIndex'] as int;
        }
        return ImageGalleryPage(galleryItems: arr, selectIndex: selectIndex);
      },
    ),
    GoRoute(
      name: '咨询详情',
      path: PageUrl.consultationDetail,
      builder: (context, state) {
        var id = state.queryParams['id'] ?? '';
        var model = state.extra as ConsultModel?;
        return ConsultationDetailPage(consultId: id, consultModel: model);
      },
    ),
    GoRoute(
      name: '医学任务数据',
      path: PageUrl.workstation,
      builder: (context, state) => const WorkstationPage(),
    ),
    GoRoute(
      name: '安全验证', // 新版钱包设置密码前的安全验证页面
      path: PageUrl.walletSecurityVerification,
      builder: (context, state) => const WalletSecurityVerificationPage(),
    ),
    GoRoute(
      name: '个人资料',
      path: PageUrl.myInfoMain,
      builder: (context, state) => const MyInfoMainPage(),
    ),
    GoRoute(
      name: '协议中心',
      path: PageUrl.myProtocolList,
      builder: (context, state) => const ProtocolListPage(),
    ),
    GoRoute(
      name: '疾病分类',
      path: PageUrl.illnessClassify,
      builder: (context, state) => const IllnessClassifyPage(),
    ),
  ],
);
